Introduction

By now you should have an app with three screens: the Onboarding , Home and Profile screens. The Onboarding screen should allow users to enter their first name, last name and email address and use a register button. The users should be able to access the Profile screen from the Home screen and log out from the Profile screen. When a user clicks on the Log out button the user's details should be removed from the device. You should also have a Home screen with a button in the header linking to the Profile screen.

In the exercises in this lesson you will focus on developing the Home screen including the hero and the menu sections. To do this, you need to fetch and store data such as menu items. In this reading, you will review some key concepts explained previously in the Android Developer program related to retrieving data from the remote server and storing the data in the app.

Fetching data

The first thing that must be recapped is that most mobile apps communicate with the back-end to retrieve data. Many mobile apps depend on data that is hosted on a remote server. To load that data in your applications, you will have to make an HTTP GET request to fetch it from the server. This can be achieved by using one of the popular networking libraries such as Ktor. The Ktor library can make network requests and handle network responses, meaning you can retrieve the data from a remote server. For example, your Little Lemon food ordering app will download the restaurant menu from an external endpoint.

Once the data is retrieved, it can then be parsed and processed by the app. Ktor can parse JSON data into Kotlin objects. To parse the received JSON data the kotlinx serialization needs to be configured. A data class will need to have a @Serializable annotation as well as the @SerialName annotation for each field.

For more detailed information about fetching data, please review the following lesson items from the Working with data in Android course :

Storing data

Data retrieved from a remote server can be stored in a local SQLite database. SQLite is a popular choice for storing data in Android applications because it is a lightweight, self-contained database engine that does not require a separate server process. It is also widely supported, with native bindings available, including Room.

Using Room in an Android app allows you to store and retrieve structured data in your device, such as user information, application settings and other types of data that need to be persisted between sessions. It also provides an easy way to query and manipulate data using SQL, which is a powerful and widely-used language for working with databases. The data in an app is stored as a database entity. One of the main advantages of using Room as persistent storage is that it allows you to store data locally on the device. This can be useful in cases where an internet connection is not available or when you want to reduce the amount of data that gets transferred between the device and a remote server. To start using Room 3 you need to:

Overall, using Room is a convenient and efficient way to store and manage data in an Android application.

For more in-depth information on storing data, please review the following lesson items from the Working with data in Android course :

Conclusion

In this reading, you recapped the key aspects of fetching data from a remote server, converting everything to a suitable Kotlin format and then storing it in the local database.